home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / SRAND.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  503 b   |  22 lines

  1.  /* srand.c from page 245*/
  2.  #include <stdio.h>
  3.  #include <stdlib.h>
  4. main()
  5. {
  6.     int i;
  7.     unsigned seed;
  8.     printf("Enter a seed: ");    /*ask user to enter a new seed*/
  9.     scanf("%u", &seed);
  10.     srand(seed);            /*set new seed by calling "srand" */
  11.  
  12.     /* Generate and display 20 pseudorandom integers */
  13.     printf("20 pseudorandom integers from \"rand\"\n");
  14.     for(i = 0; i < 20; i++)
  15.     {
  16.         printf("%d\n", rand());
  17.     }
  18.     printf("Try again with the same seed.\n\
  19.     you'll get the same sequence.\n");
  20. }
  21.  
  22.